package org.ycx.generator.step;

import org.apache.velocity.VelocityContext;
import org.ycx.common.annotation.FormDesc;
import org.ycx.common.util.StringUtil;
import org.ycx.generator.GenNode;
import org.ycx.generator.IGeneratorStep;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static org.ycx.common.util.StringUtil.humpToLine2;

/**
 * Created by 杨 on 2017-07-18.
 */
public class ServiceImplStep implements IGeneratorStep {


    public Set<String> ignoreFields = new HashSet<String>();

    private void init() {
        ignoreFields.add("createTs");
        ignoreFields.add("updateTs");
        ignoreFields.add("createUid");
        ignoreFields.add("updateUid");
        ignoreFields.add("delState");
    }

    @Override
    public VelocityContext initContext(VelocityContext context, String className) throws Exception {
        Class clazz = Class.forName(className);
        context.put("model", clazz.getSimpleName());
        context.put("fullModel", className);
        return context;
    }

    @Override
    public String getOutFileName(String loadName) {
        try {
            Class clazz = Class.forName(loadName);
            if (((FormDesc) clazz.getAnnotation(FormDesc.class)).isMidTable()) {
                return null;
            }
            String model = clazz.getSimpleName();
            return model + "ServiceImpl.java";
        } catch (ClassNotFoundException e) {
            return null;
        }
    }

    @Override
    public boolean overideFile(String loadName) {
        File file = new File(loadName);
        return !file.exists();
    }

    @Override
    public String getProjectPath(String module) {
        return System.getProperty("user.dir") + File.separator + module;
    }

    @Override
    public String getVmFile() {
        return "/templates/vm/ServiceImpl.vm";
    }
}
